package com.github.translator.util;

import java.nio.file.Path;
import java.util.Objects;

public class FileUtil {

    public static String getNameWithoutExtension(Path path){
        Objects.requireNonNull(path);
        String fileName = path.getFileName().toString();
        int dotIndex = fileName.lastIndexOf('.');
        if(dotIndex == -1){
            throw new IllegalArgumentException("File Without Extension.path="+path.toString());
        }
        return fileName.substring(0, dotIndex);
    }

    public static String getFileExtension(Path path){
        Objects.requireNonNull(path);
        String fileName = path.getFileName().toString();
        int dotIndex = fileName.lastIndexOf('.');
        if(dotIndex == -1){
            throw new IllegalArgumentException("File Without Extension.path="+path.toString());
        }
        return fileName.substring(dotIndex + 1);
    }
}
